package com.maxd.controller.banner;
import com.maxd.adapter.IgnoreSecurity;
import com.maxd.error.Result;
import com.maxd.service.banner.IBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@Api(value="广告位管理",tags={"广告位管理"})
@RequestMapping(value = "/banner")
public class BannerController {
    @Autowired
    private IBannerService iBannerService;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiOperation("管理平台广告位详情")
    @ResponseBody
    public Result getBanner(@PathVariable Integer id) {
        return iBannerService.findOne(Long.valueOf(id));
    }

    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ApiOperation("管理平台添加广告位")
    @ResponseBody
    public Result addBanner(@PathVariable String id, @RequestParam String url,@RequestParam String image,Integer type, String state) {
        return iBannerService.saveBody(id, url, image,type,state);
    }


    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ApiOperation("管理平台删除广告位")
    public Result deleteBanner(@PathVariable int id) {
        return iBannerService.delete(id);
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    @ApiOperation("管理平台获取全部广告位")
    @ResponseBody
    public Result getBannerList() {
        return iBannerService.findAll();
    }

    @RequestMapping(value = "/updateState/{id}/{state}", method = RequestMethod.POST)
    @ApiOperation("管理平台修改广告位状态")
    @ResponseBody
    public Result updateState(@PathVariable("state") String state, @PathVariable("id") String id) {
        return iBannerService.updateState(state, id);
    }
    @IgnoreSecurity
    @RequestMapping(value = "/user/list/{type}", method = RequestMethod.GET)
    @ApiOperation("用户端获取全部广告位")
    @ResponseBody
    public Result getBannerUserList(@PathVariable("type") Integer type) {
        return iBannerService.findAll(type);
    }


    @IgnoreSecurity
    @RequestMapping(value = "/user/list", method = RequestMethod.GET)
    @ApiOperation("用户端获取全部广告位")
    @ResponseBody
    public Result getBannerUserList() {
        return iBannerService.findAll(1);
    }



}
